package com.oa.cc.dao;

import java.util.List;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.oa.domain.Emp;


public class EmpDaoImpl extends HibernateDaoSupport implements EmpDao {
	public List<Emp> getEmpsByExample(Emp emp) {
		return getSession().createCriteria(Emp.class).add(Example.create(emp)).list();	
	}

	public void saveEmp(Emp emp) {
		getSession().save(emp);
		
	}

	public Emp getEmpByDeptAndRole(Emp emp) {
		/*System.out.println("部门编号："+emp.getDept().getDeptno()+"，职位编号："+emp.getOaRole().getRid());*/
		return (Emp) getSession().createQuery("from Emp where deptno="+emp.getDept().getDeptno()
				+" and rid="+emp.getOaRole().getRid()).list().get(0);	
	}

	public Emp getEmpByRoleId(Long rid) {
		/*System.out.println("职位编号："+rid);*/
		return (Emp) getSession().createQuery("from Emp where rid="+rid).list().get(0);	
	}

	public List<Emp> getEmpsByDeptno(Long deptno) {
		return getSession().createQuery("from Emp where deptno="+deptno).list();	
	}
}
